{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "92ce064a-7180-426a-85f9-7b4139937af8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "欢迎使用学生成绩管理系统\n",
      "请选择操作：\n",
      "1. 记录学生成绩\n",
      "2. 查询学生成绩\n",
      "3. 统计课程成绩\n",
      "4. 退出系统\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入选项序号： 1\n",
      "请输入学生姓名： 张三\n",
      "请输入学生学号： 2023001\n",
      "请输入课程名称： Python编程\n",
      "请输入成绩（0-100）： 95.0\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "成绩已成功记录！\n",
      "欢迎使用学生成绩管理系统\n",
      "请选择操作：\n",
      "1. 记录学生成绩\n",
      "2. 查询学生成绩\n",
      "3. 统计课程成绩\n",
      "4. 退出系统\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入选项序号： 1\n",
      "请输入学生姓名： 张三\n",
      "请输入学生学号： 2023001\n",
      "请输入课程名称： Python编程\n",
      "请输入成绩（0-100）： 95.0\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "成绩已成功记录！\n",
      "欢迎使用学生成绩管理系统\n",
      "请选择操作：\n",
      "1. 记录学生成绩\n",
      "2. 查询学生成绩\n",
      "3. 统计课程成绩\n",
      "4. 退出系统\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入选项序号： 2\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请选择查询方式：\n",
      "1. 按学生姓名查询\n",
      "2. 按学生学号查询\n",
      "3. 按课程名称查询\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入选项序号： 1\n",
      "请输入学生姓名： 张三\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "姓名：张三，学号：2023001，课程：Python编程，成绩：95.0\n",
      "姓名：张三，学号：2023001，课程：Python编程，成绩：95.0\n",
      "欢迎使用学生成绩管理系统\n",
      "请选择操作：\n",
      "1. 记录学生成绩\n",
      "2. 查询学生成绩\n",
      "3. 统计课程成绩\n",
      "4. 退出系统\n"
     ]
    }
   ],
   "source": [
    "def record_score():\n",
    "    name = input(\"请输入学生姓名：\")\n",
    "    student_id = input(\"请输入学生学号：\")\n",
    "    course = input(\"请输入课程名称：\")\n",
    "    while True:\n",
    "        try:\n",
    "            score = float(input(\"请输入成绩（0-100）：\"))\n",
    "            if 0 <= score <= 100:\n",
    "                break\n",
    "            else:\n",
    "                print(\"成绩必须在0到100之间，请重新输入。\")\n",
    "        except ValueError:\n",
    "            print(\"成绩输入无效，请输入有效的数字成绩。\")\n",
    "    students.append({\"name\": name, \"id\": student_id, \"course\": course, \"score\": score})\n",
    "    print(\"成绩已成功记录！\")\n",
    "\n",
    "\n",
    "def query_score():\n",
    "    print(\"请选择查询方式：\")\n",
    "    print(\"1. 按学生姓名查询\")\n",
    "    print(\"2. 按学生学号查询\")\n",
    "    print(\"3. 按课程名称查询\")\n",
    "    choice = input(\"请输入选项序号：\")\n",
    "    if choice == \"1\":\n",
    "        name = input(\"请输入学生姓名：\")\n",
    "        found = False\n",
    "        for student in students:\n",
    "            if student[\"name\"] == name:\n",
    "                print(f'姓名：{student[\"name\"]}，学号：{student[\"id\"]}，课程：{student[\"course\"]}，成绩：{student[\"score\"]}')\n",
    "                found = True\n",
    "        if not found:\n",
    "            print(\"未找到该学生的成绩记录。\")\n",
    "    elif choice == \"2\":\n",
    "        student_id = input(\"请输入学生学号：\")\n",
    "        found = False\n",
    "        for student in students:\n",
    "            if student[\"id\"] == student_id:\n",
    "                print(f'姓名：{student[\"name\"]}，学号：{student[\"id\"]}，课程：{student[\"course\"]}，成绩：{student[\"score\"]}')\n",
    "                found = True\n",
    "        if not found:\n",
    "            print(\"未找到该学生的成绩记录。\")\n",
    "    elif choice == \"3\":\n",
    "        course = input(\"请输入课程名称：\")\n",
    "        found = False\n",
    "        for student in students:\n",
    "            if student[\"course\"] == course:\n",
    "                print(f'姓名：{student[\"name\"]}，学号：{student[\"id\"]}，课程：{student[\"course\"]}，成绩：{student[\"score\"]}')\n",
    "                found = True\n",
    "        if not found:\n",
    "            print(\"未找到该课程的成绩记录。\")\n",
    "    else:\n",
    "        print(\"无效的查询选项，请重新运行查询功能。\")\n",
    "\n",
    "\n",
    "def statistics_score():\n",
    "    course = input(\"请输入课程名称：\")\n",
    "    scores = [student[\"score\"] for student in students if student[\"course\"] == course]\n",
    "    if scores:\n",
    "        avg_score = sum(scores) / len(scores)\n",
    "        max_score = max(scores)\n",
    "        min_score = min(scores)\n",
    "        print(f'课程：{course}')\n",
    "        print(f'平均分：{avg_score:.2f}')\n",
    "        print(f'最高分：{max_score}')\n",
    "        print(f'最低分：{min_score}')\n",
    "    else:\n",
    "        print(\"未找到该课程的成绩记录。\")\n",
    "\n",
    "\n",
    "def main_menu():\n",
    "    while True:\n",
    "        print(\"欢迎使用学生成绩管理系统\")\n",
    "        print(\"请选择操作：\")\n",
    "        print(\"1. 记录学生成绩\")\n",
    "        print(\"2. 查询学生成绩\")\n",
    "        print(\"3. 统计课程成绩\")\n",
    "        print(\"4. 退出系统\")\n",
    "        choice = input(\"请输入选项序号：\")\n",
    "        if choice == \"1\":\n",
    "            record_score()\n",
    "        elif choice == \"2\":\n",
    "            query_score()\n",
    "        elif choice == \"3\":\n",
    "            statistics_score()\n",
    "        elif choice == \"4\":\n",
    "            print(\"感谢使用学生成绩管理系统，再见！\")\n",
    "            break\n",
    "        else:\n",
    "            print(\"无效的选项，请重新输入。\")\n",
    "\n",
    "\n",
    "students = []\n",
    "if __name__ == \"__main__\":\n",
    "    main_menu()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7f214c7f-594c-49f0-abaf-a663dcf64964",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
